<template>
  <el-container class="home">
    <!-- 头部区域 -->
    <el-header>
      <img src="../../public/img/头像.png" alt />
      <h1>拼夕夕后台管理系统</h1>
      <el-button type="danger" @click="exit">退出</el-button>
    </el-header>
    <!-- 主体区域 -->
    <el-container>
      <!-- 左侧边 -->
      <el-aside :width="close_list ? '66px': '200px'">
        <!--伸缩栏-->
        <div class="toggle_button" @click="toggle">|||</div>
        <el-menu background-color="#545c64" text-color="#fff" active-text-color="#ffd04b" unique-opened :collapse='close_list' :collapse-transition='false'
        :router="true" :defaultActive="this.$route.path">
          <el-submenu :index="all_lists.id+''" v-for="all_lists in commodity" :key="all_lists.id">
            <template slot="title">
              <i :class="'el-icon-'+all_lists.icon"></i>
              <span>{{all_lists.authName}}</span>
            </template>
              <el-menu-item :index="'/'+good_list.path" v-for='good_list in all_lists.children' :key="good_list.id">
                <i :class="'el-icon-'+good_list.icon"></i>
                <span>{{good_list.listName}}</span>
              </el-menu-item>  
          </el-submenu>
        </el-menu>
      </el-aside>
      <!--右边主体  -->
      <el-main>
        
        <router-view>

        </router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data(){
    return{
      commodity:[],
      close_list:false,
      


    }
  },
  created(){
    this.getMenuList()
  },
  methods: {
    exit() {
      window.sessionStorage.clear();
      this.$router.push("/login");
      this.$notify({
        title: "通知",
        message: "已经退出",
        type: "warning"
      });
    },
    //获取所有的菜单
    async getMenuList(){
    const {data:menulist}=await this.$http.get('/js/menus.json')
    console.log(menulist);
    if(menulist.meta.status!=200) return this.$message.error(menulist.meta.msg)
    this.commodity=menulist.data
    
    },
    //点击关闭列表展开
    toggle(){
      this.close_list= !this.close_list

    }
    
}
}
</script>
<style lang="less" scoped>
.home {
  width: 100%;
  height: 100%;
}
.el-header {
  width: 100%;
  height: 100px;
  background-color: rgb(30, 25, 43);
  justify-content: space-between;
  display: flex;
  align-items: center;
}
.el-header img {
  width: 80px;
  height: 80px;
  position: relative;
  top: -5px;
}
.el-header h1 {
  color: white;
}
.el-aside {
  width: 200px;
  height: 100%;
  background-color: rgb(30, 25, 43);
}
.el-menu {
     border-right:none;
}
.toggle_button{
  height: 20px;
  background: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: white;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>